Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converts the teeth amount of a gear to the pitch diameter. #72

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Samson560915
Copy link

No description provided.

@PChild
Copy link
Member

PChild commented Dec 12, 2024

Can we add units to all of the methods please?

Copy link
Member

@jkleiber jkleiber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First pass feedback

package coppercore.math;

public class GearConversionFunctions {
public static double pitchPulley3mm(int teeth) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per #52 all these functions should return a Distance, which is a unit from wpilib. So that needs to be added to all functions.

Also you'll need to include the following in your build.gradle in the dependencies block

def wpilibVersion = "2025.1.1-beta-1"
implementation "edu.wpi.first.wpiunits:wpiunits-java:$wpilibVersion"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comparing floating point numbers with equality is generally considered bad practice. assertEquals should have an option to specify an epsilon, and I recommend setting that to 1e-10.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To use it just provide a third parameter which it the delta

Copy link
Member

@jkleiber jkleiber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another round of feedback

@@ -52,6 +52,10 @@ dependencies {

// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation libs.guava


def wpilibVersion = "2025.1.1-beta-1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should no longer be the beta version

import org.junit.jupiter.api.Test;

public class GearConversionTest {
private static final double delta = 1 * Math.pow(10.0, -10.0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, but for reference you can do:

private final double kEpsilon = 1e-10;

Comment on lines +11 to +18
Assertions.assertEquals(
12 / (Math.PI), GearConversionFunctions.pitchDiameterFrom3mmPulley(4), delta);
Assertions.assertEquals(
150 / (Math.PI), GearConversionFunctions.pitchDiameterFrom3mmPulley(50), delta);
Assertions.assertEquals(
0 / (Math.PI), GearConversionFunctions.pitchDiameterFrom3mmPulley(0), delta);
Assertions.assertEquals(
21 / (Math.PI), GearConversionFunctions.pitchDiameterFrom3mmPulley(-7), delta);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this (and other functions) a little cleaner by using arrays and a loop:

final double[] kInputs = {4.0, 50.0, 0.0, -7.0};
final double[] kExpectedOutputs = {12.0, 150.0, 0.0, 21.0};

for (int i = 0; i < kInputs.length; i++) {
    Assertions.assertEquals(kExpectedOutputs[i] / (Math.PI), GearConversionFunctions.pitchDiameterFrom3mmPulley(kInputs[i]), delta);
}

This way the test inputs and expected outputs are super clear, and the test is set up in a simple way that is easy to read

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file actually required? My intuition says no and that it should be deleted. If it is required, it should be upgraded to 2025 though

import static edu.wpi.first.units.Units.*;

public class GearConversionFunctions {
public static double pitchDiameterFrom3mmPulley(int teeth) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These functions likely will fail to compile since we are returning a Distance but saying we will return a double. We should mark this and other functions to return a Distance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add math functions to get pitch diameter of gears / sprockets / pulleys
6 participants